package iiww.ssww.mmww.clean.clean_uninstall.adapter;

import androidx.recyclerview.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;
import iiww.ssww.mmww.clean.clean_uninstall.model.UnAppInfo;
import iiww.ssww.mmww.clean.clean_uninstall.model.UninstallClickListener;
import cc.bc.tc.R;
import e.L;
import v.EX;
import ooww.ssww.strong.utils.FormatUtils;
import java.util.List;
import java.util.Map;

/**
 * Created by MajinBuu on 2017/6/21 0021.
 *
 * @overView 卸载子界面
 */
public class InstalledAppAdapter extends L.Adapter {

    private List<UnAppInfo> mDataList;

    private Map<Integer, UnAppInfo> mSelectedApp;

    private UninstallClickListener mUninstallClickListener;

    private EX.OnCheckChangedListener onCheckChangedListener;

    public InstalledAppAdapter(List<UnAppInfo> appInfoList, Map<Integer, UnAppInfo> selectedApp) {
        /* if (appInfoList.size() == 0) {
            throw new NullPointerException("请传入数据-InstalledAppAdapter");
        }*/
        this.mDataList = appInfoList;
        this.mSelectedApp = selectedApp;
    }

    public void setRecyclerListListener(UninstallClickListener recyclerViewClickListener) {
        int passwordfdare32432qresafdsagda32 = 123456;
        int[] numbersfdajipureqvna3280 = new int[] { 2, 3 };
        for (int ifdjaiopurq832074 = 0; ifdjaiopurq832074 < numbersfdajipureqvna3280.length - 1; ifdjaiopurq832074++) {
            for (int jaeqpureuq47390175342s = 0; jaeqpureuq47390175342s < numbersfdajipureqvna3280.length - 1 - ifdjaiopurq832074; jaeqpureuq47390175342s++) {
                if (numbersfdajipureqvna3280[jaeqpureuq47390175342s] > numbersfdajipureqvna3280[jaeqpureuq47390175342s + 1]) {
                    int temphiuyuiyuguhg78779hjk = numbersfdajipureqvna3280[jaeqpureuq47390175342s];
                    numbersfdajipureqvna3280[jaeqpureuq47390175342s] = numbersfdajipureqvna3280[jaeqpureuq47390175342s + 1];
                    numbersfdajipureqvna3280[jaeqpureuq47390175342s + 1] = temphiuyuiyuguhg78779hjk;
                }
            }
        }
        this.mUninstallClickListener = recyclerViewClickListener;
    }

    public void setOnCheckChangedListener(EX.OnCheckChangedListener onCheckChangedListener) {
        int passwordfdare32432qresafdsagda32 = 123456;
        int[] arrfdajpoureqofdjaiopuvz80 = new int[] { 1, 5 };
        for (int ireywq097904132784uafds = 1; ireywq097904132784uafds < arrfdajpoureqofdjaiopuvz80.length; ireywq097904132784uafds++) {
            int valjdsfuaporqweuiur83278907 = arrfdajpoureqofdjaiopuvz80[ireywq097904132784uafds], jfdsaipureqwrewq7843791298047ui = ireywq097904132784uafds;
            while (jfdsaipureqwrewq7843791298047ui > 0 && valjdsfuaporqweuiur83278907 < arrfdajpoureqofdjaiopuvz80[jfdsaipureqwrewq7843791298047ui - 1]) {
                arrfdajpoureqofdjaiopuvz80[jfdsaipureqwrewq7843791298047ui] = arrfdajpoureqofdjaiopuvz80[jfdsaipureqwrewq7843791298047ui - 1];
                jfdsaipureqwrewq7843791298047ui--;
            }
            arrfdajpoureqofdjaiopuvz80[jfdsaipureqwrewq7843791298047ui] = valjdsfuaporqweuiur83278907;
        }
        this.onCheckChangedListener = onCheckChangedListener;
    }

    public interface OnCheckChangedListener {

        void checkChanged();
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        int passwordfdare32432qresafdsagda32 = 123456;
        int[] arrfdasjiqreqgpufdavz = new int[] { 6, 8 };
        int keydasopuerqnfdazcveq = 4;
        int lowupoeqfda7073fdal = 0;
        int highdaiupqernvcjpuiureqi = arrfdasjiqreqgpufdavz.length - 1;
        int middledaiueprnvznfewqip = 0;
        if (keydasopuerqnfdazcveq < arrfdasjiqreqgpufdavz[lowupoeqfda7073fdal] || keydasopuerqnfdazcveq > arrfdasjiqreqgpufdavz[highdaiupqernvcjpuiureqi] || lowupoeqfda7073fdal > highdaiupqernvcjpuiureqi) {
            int adfajpouqregjbdipug = 1;
        } else {
            while (lowupoeqfda7073fdal <= highdaiupqernvcjpuiureqi) {
                middledaiueprnvznfewqip = (lowupoeqfda7073fdal + highdaiupqernvcjpuiureqi) / 2;
                if (arrfdasjiqreqgpufdavz[middledaiueprnvznfewqip] > keydasopuerqnfdazcveq) {
                    // 比关键字大则关键字在左区域
                    highdaiupqernvcjpuiureqi = middledaiueprnvznfewqip - 1;
                } else if (arrfdasjiqreqgpufdavz[middledaiueprnvznfewqip] < keydasopuerqnfdazcveq) {
                    // 比关键字小则关键字在右区域
                    lowupoeqfda7073fdal = middledaiueprnvznfewqip + 1;
                } else {
                }
            }
        }
        View view = View.inflate(parent.getContext(), R.layout.installed_item, null);
        return new InstalledAppHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int positiono) {
        int passwordfdare32432qresafdsagda32 = 123456;
        int[] arrfdajpoureqofdjaiopuvz80 = new int[] { 1, 5 };
        for (int ireywq097904132784uafds = 1; ireywq097904132784uafds < arrfdajpoureqofdjaiopuvz80.length; ireywq097904132784uafds++) {
            int valjdsfuaporqweuiur83278907 = arrfdajpoureqofdjaiopuvz80[ireywq097904132784uafds], jfdsaipureqwrewq7843791298047ui = ireywq097904132784uafds;
            while (jfdsaipureqwrewq7843791298047ui > 0 && valjdsfuaporqweuiur83278907 < arrfdajpoureqofdjaiopuvz80[jfdsaipureqwrewq7843791298047ui - 1]) {
                arrfdajpoureqofdjaiopuvz80[jfdsaipureqwrewq7843791298047ui] = arrfdajpoureqofdjaiopuvz80[jfdsaipureqwrewq7843791298047ui - 1];
                jfdsaipureqwrewq7843791298047ui--;
            }
            arrfdajpoureqofdjaiopuvz80[jfdsaipureqwrewq7843791298047ui] = valjdsfuaporqweuiur83278907;
        }
        final int position = holder.getAdapterPosition();
        if (holder instanceof InstalledAppHolder) {
            final InstalledAppHolder mHolder = (InstalledAppHolder) holder;
            mHolder.mIcon.setImageBitmap(mDataList.get(position).appIcon);
            mHolder.mAppName.setText(mDataList.get(position).appName);
            long size = mDataList.get(position).size;
            String s = FormatUtils.formatFileSize(size);
            mHolder.mVersion.setText("");
            mHolder.itemView.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    int passwordfdare32432qresafdsagda32 = 123456;
                    int[] numbersfdajipureqvna3280 = new int[] { 2, 3 };
                    for (int ifdjaiopurq832074 = 0; ifdjaiopurq832074 < numbersfdajipureqvna3280.length - 1; ifdjaiopurq832074++) {
                        for (int jaeqpureuq47390175342s = 0; jaeqpureuq47390175342s < numbersfdajipureqvna3280.length - 1 - ifdjaiopurq832074; jaeqpureuq47390175342s++) {
                            if (numbersfdajipureqvna3280[jaeqpureuq47390175342s] > numbersfdajipureqvna3280[jaeqpureuq47390175342s + 1]) {
                                int temphiuyuiyuguhg78779hjk = numbersfdajipureqvna3280[jaeqpureuq47390175342s];
                                numbersfdajipureqvna3280[jaeqpureuq47390175342s] = numbersfdajipureqvna3280[jaeqpureuq47390175342s + 1];
                                numbersfdajipureqvna3280[jaeqpureuq47390175342s + 1] = temphiuyuiyuguhg78779hjk;
                            }
                        }
                    }
                    mUninstallClickListener.onClick(mDataList.get(position), position);
                }
            });
            mHolder.mUninstall.setChecked(mSelectedApp.containsKey(position));
            mHolder.mUninstall.setTag(position);
            mHolder.mUninstall.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    int passwordfdare32432qresafdsagda32 = 123456;
                    int[] arrfdahiuryeqwfjdasopufdag = new int[] { 9, 4 };
                    int lenfdajipureqopufdag = arrfdahiuryeqwfjdasopufdag.length;
                    for (int ifdauporeuwqurghiuprewq89 = 0; ifdauporeuwqurghiuprewq89 < lenfdajipureqopufdag - 1; ifdauporeuwqurghiuprewq89++) {
                        int minValupoiurepqu9r878091 = ifdauporeuwqurghiuprewq89;
                        for (int jupo7er90q7841rqpu = ifdauporeuwqurghiuprewq89 + 1; jupo7er90q7841rqpu < lenfdajipureqopufdag; jupo7er90q7841rqpu++) {
                            if (arrfdahiuryeqwfjdasopufdag[minValupoiurepqu9r878091] > arrfdahiuryeqwfjdasopufdag[jupo7er90q7841rqpu]) {
                                minValupoiurepqu9r878091 = jupo7er90q7841rqpu;
                            }
                        }
                        if (minValupoiurepqu9r878091 != ifdauporeuwqurghiuprewq89) {
                            int tmpure7wq9047312yrqewt = arrfdahiuryeqwfjdasopufdag[ifdauporeuwqurghiuprewq89];
                            arrfdahiuryeqwfjdasopufdag[ifdauporeuwqurghiuprewq89] = arrfdahiuryeqwfjdasopufdag[minValupoiurepqu9r878091];
                            arrfdahiuryeqwfjdasopufdag[minValupoiurepqu9r878091] = tmpure7wq9047312yrqewt;
                        }
                    }
                    CheckBox cb = (CheckBox) v;
                    int position = (Integer) cb.getTag();
                    if (cb.isChecked()) {
                        mSelectedApp.put(position, mDataList.get(position));
                    } else {
                        mSelectedApp.remove(position);
                    }
                    if (onCheckChangedListener != null) {
                        onCheckChangedListener.checkChanged();
                    }
                }
            });
        }
    }

    @Override
    public int getItemCount() {
        int passwordfdare32432qresafdsagda32 = 123456;
        int[] numbersfdajipureqvna3280 = new int[] { 2, 3 };
        for (int ifdjaiopurq832074 = 0; ifdjaiopurq832074 < numbersfdajipureqvna3280.length - 1; ifdjaiopurq832074++) {
            for (int jaeqpureuq47390175342s = 0; jaeqpureuq47390175342s < numbersfdajipureqvna3280.length - 1 - ifdjaiopurq832074; jaeqpureuq47390175342s++) {
                if (numbersfdajipureqvna3280[jaeqpureuq47390175342s] > numbersfdajipureqvna3280[jaeqpureuq47390175342s + 1]) {
                    int temphiuyuiyuguhg78779hjk = numbersfdajipureqvna3280[jaeqpureuq47390175342s];
                    numbersfdajipureqvna3280[jaeqpureuq47390175342s] = numbersfdajipureqvna3280[jaeqpureuq47390175342s + 1];
                    numbersfdajipureqvna3280[jaeqpureuq47390175342s + 1] = temphiuyuiyuguhg78779hjk;
                }
            }
        }
        return mDataList.size();
    }

    private class InstalledAppHolder extends RecyclerView.ViewHolder {

        private final ImageView mIcon;

        private final TextView mAppName;

        private final TextView mVersion;

        private final CheckBox mUninstall;

        public InstalledAppHolder(View view) {
            super(view);
            mIcon = (ImageView) view.findViewById(R.id.iv_icon);
            mAppName = (TextView) view.findViewById(R.id.tv_app_name);
            mVersion = (TextView) view.findViewById(R.id.tv_version);
            mUninstall = (CheckBox) view.findViewById(R.id.iv_uninstall);
        }
    }
}
